<?php
/**
 * @author LonelyPersonal
 * @copyright 2012
 */
// Start XML file, create parent node
//function toXml($where){
    $dom = new DOMDocument("1.0","UTF-8");
    $node = $dom->createElement("markers");
    $parnode = $dom->appendChild($node); 
    
    // Opens a connection to a MySQL server
    
    $connection=mysql_connect ('localhost', 'root', '');
    if (!$connection) {  die('Not connected : ' . mysql_error());} 
    
    // Set the active MySQL database
    
    $db_selected = mysql_select_db('dulich', $connection);
    if (!$db_selected) {
      die ('Can\'t use db : ' . mysql_error());
    } 
    
    // Select all the rows in the markers table
    if(isset($_REQUEST['d'])){
        $query = "SELECT * FROM  location WHERE L_id = 16";
    }else{
        $query = "SELECT * FROM  location";    
    }
    
    mysql_query("SET NAMES 'utf8'");
    $result = mysql_query($query);
    if (!$result) {  
      die('Invalid query: ' . mysql_error());
    } 
    
    header("Content-type: text/xml"); 
    
    // Iterate through the rows, adding XML nodes for each
    
    while ($row = mysql_fetch_assoc($result)){  
      // ADD TO XML DOCUMENT NODE
      //echo $row['L_Name'];  
      
      //echo $convert;
      $node = $dom->createElement("marker");  
      $newnode = $parnode->appendChild($node);   
      $newnode->setAttribute("name",$row['L_Name']);
      $newnode->setAttribute("address", $row['SoDuong']);  
      $newnode->setAttribute("lat", $row['Latitude']);  
      $newnode->setAttribute("lng", $row['Longitude']);  
      $newnode->setAttribute("type", $row['St_Id']);
        
    } 
    echo  $dom->saveXML();    
//}   
//echo toXml()
?>